package com.umpay.sp.saas.action.StoreDetailed;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Preparable;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.umpay.operation.common.ReqMessage;
import com.umpay.operation.common.ResMessage;
import com.umpay.operation.common.RetCode;
import com.umpay.operation.model.applet.MerchantInfo;
import com.umpay.operation.model.product.MerProduct;
import com.umpay.operation.model.saas.StoreBatchDetail;
import com.umpay.operation.model.spapplyplat.AppChannel;
import com.umpay.operation.service.applet.StoreInfServiceRemote;
import com.umpay.operation.service.fundPurchase.FundServiceRemote;
import com.umpay.operation.service.product.MerProductServiceRemote;
import com.umpay.operation.service.saas.TStoreBatchDetailServiceRemote;
import com.umpay.operation.service.spapplyplat.remote.AppChannelServiceRemote;
import com.umpay.operation.service.spapplyplat.remote.JoinFlowServiceRemote;
import com.umpay.operation.xml.XmlData;
import com.umpay.sp.common.consdata.ConstantDefined;
import com.umpay.sp.helper.ProviceCityInfHelper;
import com.umpay.sp.model.offlinepay.ProviceCityInf;
import com.umpay.sp.saas.util.DataEntryUtil;
import com.umpay.sp.saas.util.DesIDUtil;
import com.umpay.sp.saas.util.DubboInvokerUtil;
import com.umpay.sp.saas.util.HttpUtils;
import com.umpay.sp.saas.util.ReqMessageUtil;
import com.umpay.sp.saas.util.SaasPropertyUtil;
import com.umpay.sp.saas.util.ValidateUtil;
import com.umpay.sp.util.SerialUtil;
import com.umpay.sp.util.StringUtil;
import com.umpay.sp.web.action.sys.BaseAction;
import com.umpay.sp.web.util.FileUtil;
import com.umpay.sp.web.util.PageView;
import com.umpay.sp.web.util.PropertyUtil;
import com.umpay.util.HttpUtil;

public class findStoreDetailedAction extends BaseAction implements Preparable {
	/**
	 * long:serialVersionUID
	 */
	private static final long serialVersionUID = 1L;
	// 分页	
	public static final String PRODUCTID_ADVANCESETTLE = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","productId_advanceSettle", "");
	public static final String FUND_OPEN_ACCSEARCH = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","fundOpenAccSearch", "");
	public static final String SAAS_FUNDNO = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","saas.fundNo", "");
	public static final String SAAS_FUNDMERID = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","saas.fundMerId", "");
	public static final String B_PRODUCT_ID = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","bProductId", "");
	//店铺信息接口
		StoreInfServiceRemote storeInfServiceRemote = DubboInvokerUtil.getInvoker(StoreInfServiceRemote.class);
	private PageView pageView;
	private String registerProcsState;	        
	private String storeType;
	private String storeShortName;
	private String payeeName;
	private String agentId;
	private String storeId;
	private String isNo;//修改页面
	private String returnType;//判断返回跳转/批量/单个的查询
	private String formType;//判断是否需要弹出框//查看不需要，修改需要

//	private StoreBatchDetail nowStoreBatchDetail;
	private Map nowStoreBatchDetail;
	HttpServletRequest request = ServletActionContext.getRequest();
	HttpServletResponse response = ServletActionContext.getResponse();
	private File uploadify;//用于上传
	private String uuid;//用于上传
	private String batchNo;//用于上传
	private String toType;//用于上传
	private  List<ProviceCityInf> provinceList;
	
	public String getReturnType() {
		return returnType;
	}
	public void setReturnType(String returnType) {
		this.returnType = returnType;
	}
	public String getFormType() {
		return formType;
	}
	public void setFormType(String formType) {
		this.formType = formType;
	}
	public String getIsNo() {
		return isNo;
	}
	public void setIsNo(String isNo) {
		this.isNo = isNo;
	}
	public List<ProviceCityInf> getProvinceList() {
		return provinceList;
	}
	public void setProvinceList(List<ProviceCityInf> provinceList) {
		this.provinceList = provinceList;
	}
	public String getUuid() {
		return uuid;
	}
	public void setUuid(String uuid) {
		this.uuid = uuid;
	}
	public String getBatchNo() {
		return batchNo;
	}
	public void setBatchNo(String batchNo) {
		this.batchNo = batchNo;
	}
	public String getToType() {
		return toType;
	}
	public void setToType(String toType) {
		this.toType = toType;
	}
	public File getUploadify() {
		return uploadify;
	}
	public void setUploadify(File uploadify) {
		this.uploadify = uploadify;
	}
	public PageView getPageView() {
		return pageView;
	}
	public void setPageView(PageView pageView) {
		this.pageView = pageView;
	}
	
	public Map getNowStoreBatchDetail() {
		return nowStoreBatchDetail;
	}
	public void setNowStoreBatchDetail(Map nowStoreBatchDetail) {
		this.nowStoreBatchDetail = nowStoreBatchDetail;
	}
	
	public String getRegisterProcsState() {
		return registerProcsState;
	}
	public void setRegisterProcsState(String registerProcsState) {
		this.registerProcsState = registerProcsState;
	}
	public String getStoreType() {
		return storeType;
	}
	public void setStoreType(String storeType) {
		this.storeType = storeType;
	}
	public String getStoreShortName() {
		return storeShortName;
	}
	public void setStoreShortName(String storeShortName) {
		this.storeShortName = storeShortName;
	}
	public String getPayeeName() {
		return payeeName;
	}
	public void setPayeeName(String payeeName) {
		this.payeeName = payeeName;
	}
	public String getAgentId() {
		return agentId;
	}
	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}
	public String getStoreId() {
		return storeId;
	}
	public void setStoreId(String storeId) {
		this.storeId = storeId;
	}
	/**
	 * 跳转到批次信息显示页面
	 * 
	 * @return
	 */
	public String storeDetailedCtrl(){
		return "storeDetailedTop";
	}

	/**
	 * 跳转到批次信息显示页面
	 * 
	 * @return
	 */
	public String getStoreDetailedTop(){
 		return "storeDetailedTop";
	}
	public String getStoreDetailedDown(){
		return "storeDetailedDown";
	}
	/**
	 * 批量申请明细列表查询
	 * 
	 * @return
	 */
	public String getStoreDetailedList(){
		log.info("【批量申请明细列表查询】开始");
		try{
			 String batchNo =request.getParameter("batchNo");
//		        String registerProcsState =request.getParameter("registerProcsState");//店铺状态 08:复审开通成功/03:待上传图片/06:待修改/ 11:待审核		        
//		        String storeType =request.getParameter("storeType");//申请类别0小微/1个体/2默认全部
//		        String storeShortName =request.getParameter("storeShortName");
//		        String payeeName =request.getParameter("payeeName");
//		        String agentId =request.getParameter("agentId");
//		        String storeId =request.getParameter("storeId");
		        
			String paramPage = request.getParameter("currentPage") == null ? "1" : request.getParameter("currentPage");
			pageView = new PageView(Integer.parseInt(paramPage));
		    log.info("-----前端参数batchNo= " +batchNo+"registerProcsStates ="+registerProcsState+"storeType ="+storeType+"storeShortName ="+storeShortName+"payeeName ="+payeeName+"agentId="+agentId);
	        log.info("-----前端参数storeId= " +storeId+"currentPage ="+ pageView.getCurrentpage()+"pageSize ="+ pageView.getPagecode());

			ReqMessage req = new ReqMessage();	
	  		req.put("storeType",storeType);
	  		
	  		//TODO
	  		req.put("batchNo", batchNo);
	  		req.put("registerProcsState", registerProcsState);
	  		req.put("storeShortName", storeShortName);
	  		req.put("payeeName", payeeName);		
	  		req.put("agentId", agentId);
	  		req.put("storeId", storeId);
	  		req.put("delFlag", "0");//不查询删除
	  		req.put("storeType", storeType);//不查询删除
			//当前页
	  		req.put(XmlData.CURRENT_PAGE, pageView.getCurrentpage());
			//每页条数
	  		req.put(XmlData.PAGE_SIZE, pageView.getPagecode());
			log.info("【查询批量明细列表信息】入参：" + req);
 			TStoreBatchDetailServiceRemote tStoreBatchDetailServiceRemote = DubboInvokerUtil.getInvoker(TStoreBatchDetailServiceRemote.class);
			ResMessage res = tStoreBatchDetailServiceRemote.queryBatchDetailList(req);
			log.info("【查询批量明细列表信息】出参：" + res);
 			if(!res.getRetCode().equals(ConstantDefined.SUCCESS)){
				log.info("统计批量明细列表查询失败");
				return ERROR;
			}
		//	List<StoreBatchDetail> storeBatchDetails = (List<StoreBatchDetail>) res.getValue(XmlData.STORE_BATCH_DETAIL_LIST);	
			List<Map<String, Object>> storeBatchDetails = 
					(List<Map<String, Object>>)res.getValue(XmlData.STORE_BATCH_DETAIL_LIST);
			if(storeBatchDetails != null){
				log.info("【查询批量明细列表信息】出参：" + storeBatchDetails.toString());
 			}
			
			if(storeBatchDetails != null && storeBatchDetails.size() > 0){
				pageView.setRecords(storeBatchDetails);
				//总条数
				pageView.setTotalrecord(Long.valueOf(res.getValue(XmlData.STORE_BATCH_DETAIL_COUNT).toString()));
				
			}
			request.setAttribute("pageView", pageView);
			log.info("统计批次明细列表查询成功，返回信息=" + pageView);			
		}catch(Exception e){
			e.printStackTrace();
			log.error("统计批次明细列表查询失败", e);
			return ERROR;
		}
		
		return "findListSuccess";
	}
	/**
	 * 批量申请明细查询
	 * 
	 * @return
	 */
	public String getStoreDetiledById(){
		log.info("【批量申请明细查询】开始");
		String retu ="";
		try{
			
			String uuid =  request.getParameter("uuid");
			String batchNo =request.getParameter("batchNo");
			String isNo =request.getParameter("isNo");//详情还是修改
			String storeId =  request.getParameter("storeId");//别的页面跳
			log.info("--------------------前端参数batchNo= " +batchNo+"uuid ="+isNo+"isNo ="+uuid+"storeId ="+storeId);
			if(storeId != null && !"".equals(storeId)){
				ReqMessage req = new ReqMessage();	
		  		req.put("storeId",storeId);
				log.info("【查询批量明细列表信息】入参：" + req);
 				TStoreBatchDetailServiceRemote tStoreBatchDetailServiceRemote = DubboInvokerUtil.getInvoker(TStoreBatchDetailServiceRemote.class);
				ResMessage res = tStoreBatchDetailServiceRemote.queryBatchDetailList(req);
				log.info("【查询批量明细列表信息】出参：" + res);
 				if(!res.getRetCode().equals(ConstantDefined.SUCCESS)){
					log.info("统计批量明细列表查询失败");
					//return ERROR;
				}
				List<StoreBatchDetail> storeBatchDetails = (List<StoreBatchDetail>) res.getResMap().get(XmlData.STORE_BATCH_DETAIL_LIST);	
				if(storeBatchDetails != null){
					log.info("【查询批量明细列表信息】出参：" + storeBatchDetails.toString());
					batchNo =storeBatchDetails.get(0).getBatchNo();
					uuid = storeBatchDetails.get(0).getUuid();
				}
			}
		 
			ReqMessage req = new ReqMessage();	
			req.put("uuid", uuid);
			req.put("batchNo",batchNo);//可以出来
			log.info("【查询批量明细信息】入参：" + req);
 			TStoreBatchDetailServiceRemote tStoreBatchDetailServiceRemote = DubboInvokerUtil.getInvoker(TStoreBatchDetailServiceRemote.class);
			ResMessage res = tStoreBatchDetailServiceRemote.getBatchDetailByPri(req);
			log.info("【查询批量明细信息】出参：" + res);
		
			if(!res.getRetCode().equals(ConstantDefined.SUCCESS)){
				log.info("统计批量明细查询失败");
				//return ERROR;
			}
			StoreBatchDetail storeBatchDetail = (StoreBatchDetail) res.getResMap().get(XmlData.STORE_BATCH_DETAIL);
			//身份证脱敏
			if(!"".equals(storeBatchDetail.getCategoryManCardno()) && storeBatchDetail.getCategoryManCardno() != null){
				storeBatchDetail.setCategoryManCardno(DesIDUtil.desID2Star(storeBatchDetail.getCategoryManCardno()));

			}
			//银行卡解密
			if(!"".equals(storeBatchDetail.getBankAccount()) && storeBatchDetail.getBankAccount() != null){
				storeBatchDetail.setBankAccount(DesIDUtil.decID(storeBatchDetail.getBankAccount()));

			}
			storeBatchDetail.setPayeeInidcard(DesIDUtil.desID2Star(storeBatchDetail.getPayeeInidcard()));
			
			if(storeBatchDetail != null){
				log.info("【查询批量明细信息】出参：" + storeBatchDetail.toString());
				//省市区
  				String egory = storeBatchDetail.getStoreCategory().replace("&", ",");
				storeBatchDetail.setStoreCategory(egory);
//				nowStoreBatchDetail = storeBatchDetail;
 				nowStoreBatchDetail = SaasPropertyUtil.javaBeanToMapO(storeBatchDetail);
				if(StringUtil.isNotEmpty(storeBatchDetail.getStoreId())){
					nowStoreBatchDetail.put("isStore", "1");//有商户
				}else{
					nowStoreBatchDetail.put("isStore", "0");
				}
				//显示图片
				if(StringUtil.isNotEmpty(storeBatchDetail.getImgUrl())){
					nowStoreBatchDetail.put("isUrl", "1");//有商户
				}else{
					nowStoreBatchDetail.put("isUrl", "0");
				}
				String wecatRates = (String) nowStoreBatchDetail.get("wecatRates");
				String alipayRates = (String) nowStoreBatchDetail.get("alipayRates");
				
				//nowStoreBatchDetail.put("wecatRates", Double.valueOf(wecatRates)/1000);
				//nowStoreBatchDetail.put("alipayRates",Double.valueOf(alipayRates)/1000);
				
				nowStoreBatchDetail.put("wecatRates", new BigDecimal(wecatRates).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_UP));
				nowStoreBatchDetail.put("alipayRates",new BigDecimal(alipayRates).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_UP));
			}	
			 log.info("【 【批量申请明细查询】】结束：" + nowStoreBatchDetail.toString());
			 provinceList = ProviceCityInfHelper.getAllProvice();
			 if("2".equals(isNo)){
					retu ="seeSuccess";
			}else{
				retu ="findSuccess";//详情
			}
		}catch(Exception e){	
			log.error("统计批次明细查询失败", e);
			return ERROR;
		}
		
		return retu;
	}
	public void prepare() throws Exception {

	}
	/**
	 * 批量申请明细列表删除
	 * 
	 * @return
	 */
	public void delStoreDetiledById(){
		log.info("【批量申请明细列表查询】开始");
		try{
			
			String uuid =  request.getParameter("uuid");
			String batchNo =request.getParameter("batchNo");
			log.info("-----前端参数batchNo= " +batchNo+"uuid ="+uuid);
			if(storeId != null && !"".equals(storeId)){
				ReqMessage req = new ReqMessage();	
		  		req.put("storeId",storeId);
				log.info("【查询批量明细列表信息】入参：" + req);
 				TStoreBatchDetailServiceRemote tStoreBatchDetailServiceRemote = DubboInvokerUtil.getInvoker(TStoreBatchDetailServiceRemote.class);
				ResMessage res = tStoreBatchDetailServiceRemote.queryBatchDetailList(req);
				log.info("【查询批量明细列表信息】出参：" + res);
 				if(!res.getRetCode().equals(ConstantDefined.SUCCESS)){
					log.info("统计批量明细列表查询失败");
					//return ERROR;
				}
				List<StoreBatchDetail> storeBatchDetails = (List<StoreBatchDetail>) res.getResMap().get(XmlData.STORE_BATCH_DETAIL_LIST);	
				if(storeBatchDetails != null){
					log.info("【查询批量明细列表信息】出参：" + storeBatchDetails.toString());
					batchNo =storeBatchDetails.get(0).getBatchNo();
					uuid = storeBatchDetails.get(0).getUuid();
				}
			}
						
			ReqMessage req = new ReqMessage();	
			req.put("uuid", uuid);
			req.put("batchNo",batchNo);//可以出来
			log.info("【查询批量明细信息】入参：" + req);
 			TStoreBatchDetailServiceRemote tStoreBatchDetailServiceRemote = DubboInvokerUtil.getInvoker(TStoreBatchDetailServiceRemote.class);
			ResMessage res = tStoreBatchDetailServiceRemote.getBatchDetailByPri(req);
			log.info("【查询批量明细信息】出参：" + res);
 			if(!res.getRetCode().equals(ConstantDefined.SUCCESS)){
				log.info("统计批量明细查询失败");
				//return ERROR;
			}
			StoreBatchDetail storeBatchDetail = (StoreBatchDetail) res.getResMap().get(XmlData.STORE_BATCH_DETAIL);
			if(storeBatchDetail != null){
				log.info("【查询批量明细信息】出参：" + storeBatchDetail.toString());
				
			}				 		   					
			//判断是否有商户号
			if(!"".equals(storeBatchDetail.getStoreId())){			
				String sta = storeInfDel(storeBatchDetail.getStoreId(),storeBatchDetail.getMerId());
				if("0000".equals(sta)){
					log.info("【删除批量明细信息】成功：");
				}else{
					response.getWriter().write("1");
					return;
				}
			}
			
		    //修改批量明细
			storeBatchDetail.setDelFlag("1");
			ReqMessage req2 = new ReqMessage();	
			Map<String, Object> storeMap3 = SaasPropertyUtil.javaBeanToMapO(storeBatchDetail);	
			req2.putAll(storeMap3);			
			log.info("【删除批量明细信息】入参：" + req2);
 			ResMessage res2 = tStoreBatchDetailServiceRemote.updateBatchDetailByPri(req2);
			log.info("【删除批量明细信息】出参：" + res2);
			if(!res2.getRetCode().equals(ConstantDefined.SUCCESS)){
				log.info("删除批量明细失败");
				//return ERROR;
			}
			response.getWriter().write("0");
		}catch(Exception e){		
			log.error("删除店铺失败", e);
			
		}
		
		 
	}
	/**
	 * 立码付删除接口
	 * @param merId 
	 * @param storeId 
	 * @return
	 */
	public String  storeInfDel(String storeId, String merId){
		log.info("【删除商户接口】开始--------------");
		try {
			 merId = StringUtil.trim(merId);
			 storeId = StringUtil.trim(storeId);
			if(StringUtil.isEmpty(merId)){
				log.info("获取商户号为空！");
				return ERROR;
			}
			if(StringUtil.isEmpty(storeId)){
				log.info("获取店铺号为空！");
				return ERROR;
			}
			//~~~~~~~~~~~~~~~~~~~~~~查询该收款人下所有店铺~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			ReqMessage  reqMe = ReqMessageUtil.makeOpReq();
			reqMe.put("merId" ,merId);
			reqMe.put("isDel","0");
			log.info("【查询商铺列表接口】入参：" + reqMe);
			com.umpay.operation.common.ResMessage resMe = storeInfServiceRemote.getStoreInfList(reqMe);
			log.info("【查询商铺列表接口】出参：" + resMe);
			if( !"0000".equals(resMe.getRetCode())){
				log.info("查询店铺列表接口调用失败！");
				return ERROR;
			}
			Integer totalSize = (Integer) resMe.getResMap().get("totalSize");
			List<MerchantInfo> storeInfs = (List<MerchantInfo>) resMe.getResMap().get("storeInfList");
			MerchantInfo merchantInfo = null;
			for(MerchantInfo storeDef : storeInfs){
				if(storeId.equals(StringUtil.trim(storeDef.getStoreId()))){
					merchantInfo = storeDef;
					break;
				}
			}
			String defultStore = merchantInfo.getDefultStore();
			//1.删除店铺
			if(del(merchantInfo)){
				log.info("删除店铺成功！" + storeId);
			}else{
				log.info("删除店铺失败：" + storeId);
				return ERROR;
			}
			//2.当前店铺为默认店铺且有多家店铺时，更新新的默认店铺
			if("0".equals(defultStore) && totalSize > 1){
				log.info("删除店铺为默认店铺并且店铺>1,需要重新赋值一家店铺为默认店铺");
				MerchantInfo newStoreDef = null;
				MerchantInfo newStoreDef8 = null;
				MerchantInfo newStoreDef7 = null;
				MerchantInfo newStoreDef9 = null;
				MerchantInfo newStoreDef6 = null;
				MerchantInfo newStoreDef10 = null;
				for(MerchantInfo storeDef : storeInfs){
					if(storeId.equals(StringUtil.trim(storeDef.getStoreId()))){
						continue;
					}
					String state = StringUtil.trim(storeDef.getRegisterProcsState());
					newStoreDef = storeDef;
					if("08".equals(state)){
						newStoreDef8 = storeDef;
					}else if("07".equals(state)){
						newStoreDef7 = storeDef;				
					}else if("09".equals(state)){
						newStoreDef9 = storeDef;
					}else if("06".equals(state)){
						newStoreDef6 = storeDef;
					}else if("10".equals(state)){
						newStoreDef10 = storeDef;
					}
				}
				if(newStoreDef8 != null){
					newStoreDef = newStoreDef8;
				}else if(newStoreDef7 != null){
					newStoreDef = newStoreDef7;				
				}else if(newStoreDef9 != null){
					newStoreDef = newStoreDef9;
				}else if(newStoreDef6 != null){
					newStoreDef = newStoreDef6;
				}else if(newStoreDef10 != null){
					newStoreDef = newStoreDef10;
				}
				//~~~~~~~~~~~~~~~~~~~~~~~~~~修改默认店铺~~~~~~~~~~~~~~~~~~~~~~~~~~~
				newStoreDef.setDefultStore("0");
				Map<String, Object> storeMap3 = SaasPropertyUtil.javaBeanToMapO(newStoreDef);	
				ReqMessage reqUp = ReqMessageUtil.makeOpReq();
				reqUp.putAll(storeMap3);
				log.info("【修改店铺信息接口】入参：" + reqUp);
				ResMessage resUp =  storeInfServiceRemote.updateStoreInfAll(reqUp);
				log.info("【修改店铺信息接口】出参：" + resUp);
				if(!"0000".equals(resUp.getRetCode())){
					log.info("修改默认店铺失败！");
					return ERROR;
				}
				log.info("修改默认店铺成功！新的默认店铺号为="+newStoreDef.getStoreId());
			}
			log.info("修改默认店铺成功！");
			return "0000";
		} catch (Exception e) {
			log.info("删除商户接口失败！",e);
		}	
		return ERROR;
	}

	/**
	 * 删除店铺子方法
	 * @param merchant
	 * @return
	 */
	public boolean del(MerchantInfo merchant){
		MerchantInfo merchantInfo = merchant;
		try {
			//配置文件读取子商户对应产品号
			String storeIdProductId = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","storeId.bProductId");
			String stateDel = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","storeId.bProductId.state");
			String url = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","cancelUrlStr");
			String[] productIds = storeIdProductId.split("&");
			MerProductServiceRemote merProductRemote =  DubboInvokerUtil.getInvoker(MerProductServiceRemote.class);
			for(String productId:productIds){
				log.info("注销产品关系，开始的产品号是:"+productId);
				//~~~~~~~~~~~~~~~~~~~~~根据主键查询商户商品关系接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				com.umpay.operation.common.ReqMessage reqOp = ReqMessageUtil.makeOpReq();
				reqOp.put("merId",merchantInfo.getStoreId());
				reqOp.put("productId",productId);
				log.info("【根据主键查询商户商品关系接口】入参："+ reqOp);
				com.umpay.operation.common.ResMessage resOp = merProductRemote.getMerProductByKey(reqOp);
				log.info("【根据主键查询商户商品关系接口】出参："+ resOp);
				if( !RetCode.SUCCESS.equals(resOp.getRetCode())){
					log.info("根据主键查询商户商品关系接口调用失败：");
					return false;
				}
				MerProduct merProduct = (com.umpay.operation.model.product.MerProduct) resOp.getResMap().get("merProduct");
				if(merProduct != null){
					//~~~~~~~~~~~~~~~~~~~~~注销产品关系接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					log.info("商户已开通此产品:" + productId );
					String cancelUrlStr = url + "UnRegMerAccount/"+ "MerProductStateCancel.xml";
					log.info("注销产品关系请求url：" + url);
					Map<String,Object> reqMap=new HashMap<String,Object>();
					String rpidCrm = "sPweb" + SerialUtil.getRpid("merRpid", 10);
					reqMap.put("rpid", rpidCrm);
					reqMap.put("merId",merchantInfo.getStoreId());
					reqMap.put("productId",productId);
					log.info("【注销产品关系接口】入参："+ reqMap);
					XStream xstream = new XStream(new DomDriver());
			        Map<String,Object> crmresMap=(Map<String, Object>)HttpUtils.getResObjPost(cancelUrlStr, xstream, reqMap);
			        log.info("【注销产品关系接口】出参："+ crmresMap);
			        if (!("0000".equals(StringUtil.trim(crmresMap.get("retCode")))) && !"00060403".equals(StringUtil.trim(crmresMap.get("retCode")))) {
						log.info("通过crm注销产品关系失败");
						return false;
			        }
			        if( "00060403".equals(StringUtil.trim(crmresMap.get("retCode")))){
			        	log.info("用户本处于注销状态");
			        }
					log.info("注销商户产品关系成功storeId:" + merchantInfo.getStoreId()+ "productId：" + productId);
				}
				if(merProduct == null){
					log.info("商户未开通此产品storeId：" + merchantInfo.getStoreId() + "productId:" + productId);
				}
				}
			//~~~~~~~~~~~~~~~~~~~~~修改店铺信息接口~~~~~~~~~~~~~~~~~~~~~~~~~~~
			ReqMessage reqStor = ReqMessageUtil.makeOpReq();
			merchantInfo.setIsDel("1");
			log.info("变更为'已删除’插入操作记录 ------");	
			addJoinFlowForDelMer(merchantInfo);
			Map<String, Object> storeMap3 = SaasPropertyUtil.javaBeanToMapO(merchantInfo);	
			reqStor.putAll(storeMap3);
			log.info("【修改店铺信息接口】入参：" + reqStor);
			ResMessage resStor =  storeInfServiceRemote.updateStoreInfAll(reqStor);
			log.info("【修改店铺信息接口】出参：" + resStor);
			if(!"0000".equals(resStor.getRetCode())){
				log.info("修改店铺信息接口调用失败！");
				return false;
			}
			log.info("修改店铺信息接口成功！已删除店铺：" + merchantInfo.getStoreId());
			return true;
		} catch (Exception e) {
			log.info("删除店铺失败",e);
			return false;
		}
	}
	/**
	 * 修改批量申请明细
	 * 
	 * @return
	 */
	public String updateStoreDetailed(){
		log.info("【修改批量申请明查询】开始");
		try{
			//前台参数
	        String uuid =  request.getParameter("uuid");
	        String batchNo = request.getParameter("batchNo");
	        String agentId = request.getParameter("agentId");//前台加上
	        
	        String phone = request.getParameter("phone");//客服电话
	        String email = request.getParameter("email");//商户邮箱
	        String storeType = request.getParameter("storeType");//商户类型
	        
	        String storeCategory1 = request.getParameter("storeCategory1");
	        String storeCategory2 = request.getParameter("storeCategory2");
	        String storeCategory3 = request.getParameter("storeCategory3");
	        String storeCategory =  "";//商户类别
	        if(StringUtil.isNotEmpty(storeCategory3)){
	        	storeCategory=storeCategory1+"&"+storeCategory2+"&"+storeCategory3;
	        }else{
	        	storeCategory=storeCategory1+"&"+storeCategory2;
	        }
	              
	        String storeAddrProv = request.getParameter("storeAddrProv");//商户地址/省
	        String storeAddrCity = request.getParameter("storeAddrCity");//商户地址/市
	        if(storeAddrCity == null ){
	        	storeAddrCity = "";
	        }
	        String storeAddrArea = request.getParameter("storeAddrArea");//商户地址/区
	        String labelOne = request.getParameter("labelOne");//标签一
	        String labelTwo = request.getParameter("labelTwo");//标签二
	        String storeFullAddr = request.getParameter("storeFullAddr");//商户详细地址
	        
	        String storeShortName = request.getParameter("storeShortName");//商户简称
	      
	        String payeeName = request.getParameter("payeeName");//收款人姓名
	        String payeeInidcard = request.getParameter("payeeInidcard");//收款人身份证号        
	        
	        String payeeInidcardValid = request.getParameter("payeeInidcardValid");//收款人身份证有效期
	        String payeeMobileId = request.getParameter("payeeMobileId");//收款人手机号码     
	        
	        String bankAccount = request.getParameter("bankAccount");//银行账号
	        String prestorePhone = request.getParameter("prestorePhone");//银行预留手机号
	        
	        String salesmanId = request.getParameter("salesmanId");//业务员编号
	        String licenseNo = request.getParameter("licenseNo");//个体商户营业执照号
	        String storeFullName = request.getParameter("storeFullName");//个体商户全称
	        String categoryManName = request.getParameter("categoryManName");//经营者姓名
	        String categoryManCardno = request.getParameter("categoryManCardno");//经营者身份证号码
	        
	        String categoryInidcardValid = request.getParameter("categoryInidcardValid");//经营者身份证有效期
	        String registerDate = request.getParameter("registerDate");//注册日期
	        String mainBusiness = request.getParameter("mainBusiness");//主营业务
	        String rgstaddress = request.getParameter("rgstaddress");//注册地址
	       
	        String wecatRates = request.getParameter("wecatRates");//立马付微信费率（%）
	        String alipayRates = request.getParameter("alipayRates");//立马付支付宝费率（%）
	        
	        String codeOne = request.getParameter("codeOne");//固码1
	        String codeTwo = request.getParameter("codeTwo");//固码2
	        String codeThree = request.getParameter("codeThree");//固码3
	        String codeFour = request.getParameter("codeFour");//固码4
	        log.info("-----前端参数batchNo= " +batchNo+"uuid ="+uuid+"phone ="+phone+"email ="+email+"storeType ="+storeType+"storeCategory="+storeCategory);
	        log.info("-----前端参数storeCategory= " +storeCategory+"storeAddrProv ="+ storeAddrProv+"storeAddrCity ="+ storeAddrCity);
	        log.info("-----前端参数storeAddrArea= " +storeAddrArea+"labelOne ="+labelOne+"labelTwo ="+labelTwo+"storeFullAddr ="+storeFullAddr+"storeShortName ="+storeShortName+"payeeName="+payeeName);
	        log.info("-----前端参数payeeInidcard= " +payeeInidcard+"payeeInidcardValid ="+payeeInidcardValid+"payeeMobileId ="+payeeMobileId+"bankAccount ="+bankAccount+"prestorePhone ="+prestorePhone+"salesmanId="+salesmanId);
	        log.info("-----前端参数licenseNo= " +licenseNo+"storeFullName ="+storeFullName+"categoryManName ="+categoryManName+"categoryManCardno ="+categoryManCardno+"categoryInidcardValid ="+categoryInidcardValid+"registerDate="+registerDate);
	        log.info("-----前端参数mainBusiness= " +mainBusiness+"rgstaddress ="+rgstaddress+"wecatRates ="+wecatRates+"alipayRates ="+alipayRates+"codeOne ="+codeOne+"codeTwo="+codeTwo);
	        log.info("-----前端参数codeThree= " +codeThree+"codeFour ="+ codeFour);

	        
	        
	        //查询批量明细
	        ReqMessage req = new ReqMessage();	
			req.put("uuid", uuid);
			req.put("batchNo",batchNo);//可以出来
			log.info("【查询批量明细信息】入参：" + req);
 			TStoreBatchDetailServiceRemote tStoreBatchDetailServiceRemote = DubboInvokerUtil.getInvoker(TStoreBatchDetailServiceRemote.class);
			ResMessage res = tStoreBatchDetailServiceRemote.getBatchDetailByPri(req);
			log.info("【查询批量明细信息】出参：" + res);
 			if(!res.getRetCode().equals(ConstantDefined.SUCCESS)){
				log.info("统计批量明细查询失败");
				//return ERROR;
			}
			StoreBatchDetail storeBatchDetail = (StoreBatchDetail) res.getResMap().get(XmlData.STORE_BATCH_DETAIL);
			if(storeBatchDetail != null){
				log.info("【查询批量明细信息】出参：" + storeBatchDetail.toString());
 //				nowStoreBatchDetail = storeBatchDetail;
				
			}	
 			if(payeeName == null || "".equals(payeeName)){
				payeeName = storeBatchDetail.getPayeeName();
			}
			//收款人身份证号 
			if(payeeInidcard == null){
				payeeInidcard =DesIDUtil.decID(storeBatchDetail.getPayeeInidcard());
			}else{
				if(payeeInidcard.contains("***")){
					payeeInidcard = DesIDUtil.decID(storeBatchDetail.getPayeeInidcard());
			    } 
			}
			//经营者身份证号码
			if(categoryManCardno == null){
				 
			}else{
				if(categoryManCardno.contains("***")){
					 categoryManCardno = DesIDUtil.decID(storeBatchDetail.getCategoryManCardno());
			    }    
			}

			//判断是否开商户
		    if(!StringUtils.isBlank(storeBatchDetail.getStoreId())){
		    	 //修改通过的字段--不需要校验的数据   批量明细
		    	 Map<String, Object> trueMap = new HashMap<String, Object>();
		    	 //更新之前查询店铺
		    	 ReqMessage req2 = new ReqMessage();		
		 		 req2.put("storeId",storeBatchDetail.getStoreId());	//店铺编号
		 		 log.info("【查询店铺信息】入参：" + req2);
		 		 StoreInfServiceRemote storeInfServiceRemote = DubboInvokerUtil.getInvoker(StoreInfServiceRemote.class);
		 		 ResMessage res2 = storeInfServiceRemote.getStoreInfByPri(req2);
		 		 log.info("【查询店铺信息】出参：" + res2);
 		 		 if(!res2.getRetCode().equals(ConstantDefined.SUCCESS)){
		 			 log.info("统计批次列表查询失败");
		 			//return ERROR;
		 		 }
		 		 MerchantInfo merchantInfo = (MerchantInfo) res2.getValue("merchantInfo");			
		 		 if(merchantInfo != null){
		 			log.info("【查询店铺列表信息】入参：" + merchantInfo.toString());
 		 		 }
		    	 
		    	//修改通过的字段-- 不需要校验的数据  店铺
		    	 Map<String, Object> trueMapStore = new HashMap<String, Object>();
		    	 trueMap.put("phone",phone);
		    	 trueMap.put("email",email);
		    	 trueMap.put("storeCategory",storeCategory);//商户类别
 		    	 trueMap.put("storeAddrProv",storeAddrProv);//省市区
 		    	 trueMap.put("storeAddrCity",storeAddrCity);
 		    	 if(StringUtil.isNotEmpty(storeAddrArea)){
 		    		 trueMap.put("storeAddrArea",storeAddrArea);
 		    	 }	    	
		    	 trueMap.put("labelOne",labelOne);
		    	 trueMap.put("labelTwo",labelTwo);
		    	 trueMap.put("storeFullAddr",storeFullAddr);
		    	 
		    	 trueMapStore.put("phone",phone);
		    	 trueMapStore.put("email",email);
		    	 trueMapStore.put("storeType",storeType);
		    	 trueMapStore.put("storeCategory",storeCategory);
		    	 trueMapStore.put("storeAddrProv",storeAddrProv);
		    	 trueMapStore.put("storeAddrCity",storeAddrCity);
		    	 if(StringUtil.isNotEmpty(storeAddrArea)){
		    		 trueMapStore.put("storeAddrArea",storeAddrArea);
 		    	 }
		    	 trueMapStore.put("labelOne",labelOne);
		    	 trueMapStore.put("labelTwo",labelTwo);
		    	 trueMapStore.put("storeFullAddr",storeFullAddr);
		    	 
		    	 
		    	 //存在店铺判断是否可以修改	 1.业务员2.店铺重名3.手机号（可以修改会修改所有子店铺） 
		    	 //4.证件有效期（直接修改）//5.是否能改为小微//6.银行卡和手机号7.法人姓名.验证法人证件号.法人证件有效期
		    	 //8. 验证立马付微信、支付宝费率 agentId wecatRates alipayRates/9.固码codeOne codeTwo codeThree codeFour
		    	 //	个体licenseNo,storeFullName,categoryManName,categoryManCardno,categoryInidcardValid,registerDate,mainBusiness,rgstaddress
		    	 
		    	 Map s = vaidStore(trueMap,trueMapStore,storeBatchDetail,salesmanId,
		    			 storeShortName,payeeMobileId,payeeInidcardValid,storeType,bankAccount,
		    			 prestorePhone,categoryManName,categoryManCardno,categoryInidcardValid,
		    			 agentId,wecatRates,alipayRates,codeOne ,codeTwo ,codeThree ,codeFour,
		    		        licenseNo,storeFullName, registerDate,mainBusiness,rgstaddress,payeeInidcard);
		 		 log.info("校验的出参" + s.toString());
		    	 String failReason  = (String) s.get("failReason");//失败原因
		    	 trueMap  =  (Map<String, Object>) s.get("trueMap");
		    	 trueMapStore  =  (Map<String, Object>) s.get("trueMapStore");
		    	 //判断店铺和批量的状态
		    	//修改成功并且照片已经上传，加入joinflow
		  		if("".equals(failReason)){
		  			if("".equals(storeBatchDetail.getImgUrl())){
		  				//08:复审开通成功06:待修改03:待上传图片07:待审核
		  				merchantInfo.setRegisterProcsState("03");
		  				storeBatchDetail.setRegisterProcsState("03");
		  			}else{
		  				merchantInfo.setRegisterProcsState("07");
		  				storeBatchDetail.setRegisterProcsState("07");
		  				//加入审批流程表
		  				log.info("变更为‘待复查’插入操作记录 ------");	
		  				addJoinFlowForCheckMer(merchantInfo);
		  			}
		  		}
		    	 //更新店铺--
		    	 ReqMessage req3 = new ReqMessage();	
		 		 Map<String, Object> storeMap = SaasPropertyUtil.javaBeanToMapO(merchantInfo);	
		 		 req3.putAll(storeMap);
		 		 req3.putAll(trueMapStore);
		 		 log.info("【修改店铺信息】修改的参数：" + trueMapStore.toString());
		 		 log.info("【修改店铺信息】入参：" + req3);
 		  		 ResMessage res3 = storeInfServiceRemote.updateStoreInfAll(req3);
		 		 log.info("【修改店铺信息】出参：" + res3);
 		 		 if(!res3.getRetCode().equals(ConstantDefined.SUCCESS)){
		 			log.info("修改店铺信息失败");
		 			//return ERROR;
		 		 }
		 		 //更新批量明细
				ReqMessage req4 = new ReqMessage();	
				storeBatchDetail.setFailReason(failReason);
				Map<String, Object> storeMap4= SaasPropertyUtil.javaBeanToMapO(storeBatchDetail);	
				req4.putAll(storeMap4);	
				req4.putAll(trueMap);	
				 log.info("【修改批量明细信息】修改的参数：" + trueMap.toString());
				log.info("【修改批量明细信息】入参：" + req);
 				ResMessage res4 = tStoreBatchDetailServiceRemote.updateBatchDetailByPri(req4);
				log.info("【修改批量明细信息】出参：" + res4);
 		 		 
		    }else{
		    	//开户之前校验所有参数是否修改
		    	 //修改通过的字段--不需要校验的数据   批量明细
		    	 Map<String, Object> trueMap = new HashMap<String, Object>();
		    	 
		    	 trueMap.put("phone",phone);
		    	 trueMap.put("email",email);
		    	 trueMap.put("storeCategory",storeCategory);//商户类别
 		    	 trueMap.put("storeAddrProv",storeAddrProv);//省市区
 		    	 trueMap.put("storeAddrCity",storeAddrCity);
 		    	 if(StringUtil.isNotEmpty(storeAddrArea)){
 		    		 trueMap.put("storeAddrArea",storeAddrArea);
 		    	 }	    	
		    	 trueMap.put("labelOne",labelOne);
		    	 trueMap.put("labelTwo",labelTwo);
		    	 trueMap.put("storeFullAddr",storeFullAddr);
		    	 trueMap.put("storeShortName",storeShortName);
		    	 //判断批量明细修改    1.业务员2.店铺重名3.手机号（可以修改会修改所有子店铺）   payeeName,payeeInidcard,payeeInidcardValid,payeeMobileId
		    	 //4.证件有效期（直接修改）//5.是否能改为小微//6.银行卡和手机号7.法人姓名.验证法人证件号.法人证件有效期
		    	 //8. 验证立马付微信、支付宝费率 agentId wecatRates alipayRates/9.固码codeOne codeTwo codeThree codeFour	 
		    	 Map s = vaidStoreBatchDetail(trueMap,storeBatchDetail,salesmanId,
		    			 storeShortName,payeeMobileId,payeeInidcardValid,storeType,bankAccount,
		    			 prestorePhone,categoryManName,categoryManCardno,categoryInidcardValid,
		    			 agentId,wecatRates,alipayRates,codeOne ,codeTwo ,codeThree ,codeFour,payeeName,payeeInidcard,
		    			 licenseNo,storeFullName, registerDate,mainBusiness,rgstaddress);
		    	 log.info("校验的出参" + s.toString());
		    	 String failReason  = (String) s.get("failReason");//失败原因
		    	 trueMap  =  (Map<String, Object>) s.get("trueMap");
		    	 if(!"".equals(failReason)){
		    		//失败 -更新批量明细
		    		//更新批量明细
					ReqMessage req4 = new ReqMessage();	
					storeBatchDetail.setFailReason(failReason);
					Map<String, Object> storeMap4= SaasPropertyUtil.javaBeanToMapO(storeBatchDetail);	
					req4.putAll(storeMap4);	
					req4.putAll(trueMap);	
					log.info("【修改批量明细信息】入参：" + req);
 					ResMessage res4 = tStoreBatchDetailServiceRemote.updateBatchDetailByPri(req4);
					log.info("【修改批量明细信息】出参：" + res4);
 		    	 }else{
		    		 //成功
		    		 //1.开通商户
		    		 ReqMessage reqSto = new ReqMessage();
		    		 ResMessage resDetail = null;
		    		 storeBatchDetail.setFailReason("");
		    		 Map<String, Object> storeMap4= SaasPropertyUtil.javaBeanToMapO(storeBatchDetail);
		    		 reqSto.putAll(storeMap4);
		    		 reqSto.putAll(trueMap);	
		    		 resDetail = DataEntryUtil.createStore(reqSto);
		    		 
		    		 //2.判断是否成功
		    		 String failReason2  ="";//失败原因
		    		
					
		    		 if(!resDetail.getValue("retCode").equals("0000")){
		    			 //不成功更新失败原因
		    			//更新批量明细
						ReqMessage req4 = new ReqMessage();	
						//TODOretMsg
						storeBatchDetail.setFailReason((String) resDetail.getValue("retMsg"));
						Map<String, Object> storeMap5= SaasPropertyUtil.javaBeanToMapO(storeBatchDetail);	
						req4.putAll(storeMap5);	
						req4.putAll(trueMap);	
						log.info("【修改批量明细信息】入参：" + req);
 						ResMessage res4 = tStoreBatchDetailServiceRemote.updateBatchDetailByPri(req4);
						log.info("【修改批量明细信息】出参：" + res4);
		    			 
		    		 }else{
		    			 String eStoreId = (String) resDetail.getValue("storeId");//成功后返回的id
 		    			 //查询店铺
		    			 ReqMessage req9 = new ReqMessage();		
	    				req9.put("storeId",eStoreId);	//店铺编号
	    				log.info("【查询店铺信息】入参：" + req9);
	    				StoreInfServiceRemote storeInfServiceRemote = DubboInvokerUtil.getInvoker(StoreInfServiceRemote.class);
	    				ResMessage res9 = storeInfServiceRemote.getStoreInfByPri(req9);
	    				log.info("【查询店铺信息】出参：" + res);
 	    				if(!res9.getRetCode().equals(ConstantDefined.SUCCESS)){
	    						log.info("统计批次列表查询失败");
	    						//return ERROR;
	    				}
	    				MerchantInfo merchantInfo = (MerchantInfo) res9.getValue("merchantInfo");			
	    				if(merchantInfo != null){
	    						log.info("【查询店铺列表信息】入参：" + merchantInfo.toString());	    					
	    				}		    			
		    			 //更新批量明细
		    			 if("".equals(storeBatchDetail.getImgUrl())){
				  				//08:复审开通成功06:待修改03:待上传图片07:待审核
				  			 
				  				storeBatchDetail.setRegisterProcsState("03");
				  				merchantInfo.setRegisterProcsState("03");//待上传图片
				  		}else{
				  				storeBatchDetail.setRegisterProcsState("07");
				  				merchantInfo.setRegisterProcsState("07");//待审核
				  				//加入审批流程表
				  				log.info("变更为‘待复查’插入操作记录 ------");	
				  				addJoinFlowForCheckMer(merchantInfo);
				  				
				  		}
		    			//更新店铺状态 --待修改
	    				//查询-修改		    				    
    					ReqMessage req2 = new ReqMessage();	   					
    					Map<String, Object> storeMap3 = SaasPropertyUtil.javaBeanToMapO(merchantInfo);	
    					req2.putAll(storeMap3);		    					
    					log.info("【修改店铺信息】入参：" + req2);
	    			 		ResMessage res2 = storeInfServiceRemote.updateStoreInfAll(req2);
    					log.info("【修改店铺信息】出参：" + res2);
	    					if(!res2.getRetCode().equals(ConstantDefined.SUCCESS)){
    						log.info("修改店铺信息失败");
    					}
		    			ReqMessage req4 = new ReqMessage();	
		    			storeBatchDetail.setMerId(merchantInfo.getMerId());
		    			storeBatchDetail.setStoreId(merchantInfo.getStoreId());
		    			storeBatchDetail.setFailReason("");
						Map<String, Object> storeMap5= SaasPropertyUtil.javaBeanToMapO(storeBatchDetail);
						req4.putAll(storeMap5);
						req4.putAll(trueMap);
							//TODO
						req4.put("storeId",merchantInfo.getStoreId());
						req4.put("merId",merchantInfo.getMerId());
						log.info("【修改批量明细信息】入参：" + req);
 						ResMessage res4 = tStoreBatchDetailServiceRemote.updateBatchDetailByPri(req4);
						log.info("【修改批量明细信息】出参：" + res4);
		    		 }
		    	 }
		    }	        			 		   					
			
		}catch(Exception e){
			log.error("修改店铺失败", e);
			return ERROR;
		}
		
		return "updateSuccess";
	}
	//开户之前的校验
	private Map vaidStoreBatchDetail(Map<String, Object> trueMap,
			StoreBatchDetail storeBatchDetail, String salesmanId,
			String storeShortName, String payeeMobileId, String payeeInidcardValid, 
			String storeType, String bankAccount, String prestorePhone, String categoryManName, 
			String categoryManCardno, String categoryInidcardValid, String agentId,
			String wecatRates, String alipayRates, String codeOne, String codeTwo, String codeThree, String codeFour, 
			String payeeName, String payeeInidcard,
			String licenseNo, String storeFullName, String registerDate, String mainBusiness, String rgstaddress) {
		 StringBuffer failReason =new StringBuffer();
		 //1---------------是否修改了业务员编号--公共
//	   	 if(!salesmanId.equals(storeBatchDetail.getSalesmanId())){
	   		//验证业务员编号是否正确
	   		 try {
	   			 	log.info("----#---------#-验证业务员编号开始--#---------#--");
					Map<String, String> map = ValidateUtil.salesmanId(storeBatchDetail.getAgentId(),salesmanId);
					log.info("----#---------#-验证业务员编号结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("salesmanId",salesmanId);
					
					}
				} catch (Exception e) {
					log.error("----#---------#-验证业务员编号失败--#---------#--",e);
				}
//	   	 }
	   	 //2-----------------是否修改了店铺简称--公共
////	   	 if(!storeShortName.equals(storeBatchDetail.getStoreShortName())){
//	   		//验证店铺简称是否正确
	   		/* try {
	   			 	log.error("----#---------#-验证店铺简称开始--#---------#--");
					Map<String, String> map = ValidateUtil.storeShortSame(storeShortName,storeBatchDetail.getMerId());
					log.error("----#---------#-验证店铺简称结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retmsg"));
						
					}else{
						trueMap.put("storeShortName",storeShortName);
					}
				} catch (Exception e) {
					log.error("----#---------#-验证店铺简称失败--#---------#--");
				}*/
//	   	 }
	   //3-----------------是否修改了收款人，手机号，有效期，身份证号 payeeName,payeeInidcard,payeeInidcardValid,payeeMobileId
//	   	 if(!payeeName.equals(storeBatchDetail.getPayeeName()) ||!payeeInidcard.equals(storeBatchDetail.getPayeeInidcard()) 
//	   			 ||!payeeInidcardValid.equals(storeBatchDetail.getPayeeInidcardValid()) || !payeeMobileId.equals(storeBatchDetail.getPayeeMobileId()) ){
	   		//验证手机号是否正确
	   		 try {
	   			 //TODO
		   			log.info("----#---------#-验证验证收款人四要素开始--#---------#--");
					Map<String, String> map = ValidateUtil.identityInfo(payeeName,payeeInidcard,payeeInidcardValid,payeeMobileId);
					log.info("----#---------#验证收款人四要素结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						String mer = map.get("merId");
						if(mer != null ||!"".equals(mer)){
							trueMap.put("merId",map.get("merId"));//merId
						}
					
						trueMap.put("defultStore",map.get("defultStore"));//默认店铺
						
						trueMap.put("payeeName",payeeName);
						trueMap.put("payeeInidcard",DesIDUtil.encID(payeeInidcard));
						trueMap.put("payeeInidcardValid",payeeInidcardValid);
						trueMap.put("payeeMobileId",payeeMobileId);
					}
						
				} catch (Exception e) {
					log.error("----#---------#-验证收款人四要素失败--#---------#--",e);
				}
//	   	 }
	   	
	     //5---------------是否修改了小微--公共
	   	 //TODO
//	   	 if(!storeType.equals(storeBatchDetail.getStoreType())){
//	   		//验证修改了小微	//判断是否可以改为小微
//	   		 if("0".equals(storeType)){
//	   			 
//	   		 }
//	   		 
//	   	 }else{
	   		 //是个体的话判断是否修改-
	   		 if("1".equals(storeType)){
	   		   	 //7---------------是否修改了法人姓名.验证法人证件号.法人证件有效期--公共 categoryManName categoryManCardno categoryInidcardValid
	   			if(!categoryManName.equals(storeBatchDetail.getCategoryManName()) || !categoryManCardno.equals(storeBatchDetail.getCategoryManCardno()) 
			   			 ||  !categoryInidcardValid.equals(storeBatchDetail.getCategoryInidcardValid())){
			   		//验证业务员编号是否正确
			   		 try {
			   			 	log.info("----#---------#-验证法人姓名.验证法人证件号.法人证件有效期开始--#---------#--");
							Map<String, String> map = ValidateUtil.storeManIdentity(categoryManName,categoryManCardno,categoryInidcardValid);
							log.info("----#---------#-验证法人姓名.验证法人证件号.法人证件有效期结束--#---------#--"+map.toString());
							if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
								failReason.append(map.get("retMsg"));
								failReason.append("|");
							}else{
								trueMap.put("categoryManName",categoryManName);
								trueMap.put("categoryManCardno",DesIDUtil.encID(categoryManCardno));
								trueMap.put("categoryInidcardValid",categoryInidcardValid);
								
							}
						} catch (Exception e) {
							log.error("----#---------#-验证法人姓名.验证法人证件号.法人证件有效期失败--#---------#--",e);
						}
			   	 }
	   			trueMap.put("storeType","1");	
	   			trueMap.put("licenseNo",licenseNo);
				trueMap.put("storeFullName",storeFullName);
				trueMap.put("registerDate",registerDate);
				trueMap.put("mainBusiness",mainBusiness);
				trueMap.put("registerDate",registerDate);
				trueMap.put("rgstaddress",rgstaddress);	
	   		 }else{
	   			trueMap.put("storeType","0");	
 				trueMap.put("licenseNo","");
				trueMap.put("storeFullName","");
				trueMap.put("registerDate","");
				trueMap.put("mainBusiness","");
				trueMap.put("registerDate","");
				trueMap.put("rgstaddress","");									
				trueMap.put("categoryManName","");
				trueMap.put("categoryManCardno","");
				trueMap.put("categoryInidcardValid","");
	   		 }
//	   	 }
		 //6---------------是否修改了银行卡和手机号--公共
//	   	 if(!bankAccount.equals(storeBatchDetail.getBankAccount()) || !prestorePhone.equals(storeBatchDetail.getPrestorePhone())){
	   		//验证业务员编号是否正确
	   		 try {
	   			 	log.info("----#---------#-验证银行卡和手机号开始--#---------#--");
					Map<String, String> map = ValidateUtil.bankAccount(payeeName,payeeInidcard,bankAccount,prestorePhone);
					log.info("----#---------#-验证银行卡和手机号结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("bankAccount",DesIDUtil.encID(bankAccount));
						trueMap.put("prestorePhone",prestorePhone);
//						trueMapStore.put("prestorePhone",prestorePhone);
//						trueMapStore.put("prestorePhone",prestorePhone);
					}
				} catch (Exception e) {
					log.error("----#---------#-验证银行卡和手机号失败--#---------#--",e);
				}
//	   	 }	   	
	   	 //8---------------是否修改了验证立马付微信、支付宝费率 agentId wecatRates alipayRates--公共
//	   	 if(!wecatRates.equals(storeBatchDetail.getWecatRates()) || !alipayRates.equals(storeBatchDetail.getAlipayRates())){
	   		//验证立马付微信、支付宝费是否正确
	   		 try {
	   			 	log.info("----#---------#-验证立马付微信、支付宝费开始--#---------#--");
					Map<String, String> map = ValidateUtil.rate(agentId,wecatRates,alipayRates);
					log.info("----#---------#-验证立马付微信、支付宝费结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
//						trueMap.put("wecatRates",wecatRates);
						trueMap.put("wecatRates",wecatRates.equals("") ? "" : (new BigDecimal(wecatRates).multiply(new BigDecimal(1000))).intValue());//立马付微信费率（%）
						trueMap.put("alipayRates",alipayRates.equals("") ? "" : (new BigDecimal(alipayRates).multiply(new BigDecimal(1000))).intValue());//立马付支付宝费率（%）

//						trueMap.put("alipayRates",alipayRates);

					}
				} catch (Exception e) {
					log.error("----#---------#-验证立马付微信、支付宝费失败--#---------#--",e);
				}
//	   	 }
	   //9---------------是否修改了.固码codeOne codeTwo codeThree codeFour--公共
//	   	 if(!codeOne.equals(storeBatchDetail.getCodeOne())){
	   		//验证固码1是否正确
	   		 try {
	   			 	log.info("----#---------#-验证固码1开始--#---------#--");
					Map<String, String> map = ValidateUtil.codeOne(codeOne);
					log.info("----#---------#-验证固码1结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("codeOne",codeOne);
		
					}
				} catch (Exception e) {
					log.error("----#---------#-验固码1失败--#---------#--",e);
				}
//	   	 }
//	   	if(!codeTwo.equals(storeBatchDetail.getCodeTwo())){
	   		//验证固码2是否正确
	   		 try {
	   			 	log.info("----#---------#-验证固码2开始--#---------#--");
					Map<String, String> map = ValidateUtil.codeTwo(codeTwo);
					log.info("----#---------#-验证固码2结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("codeTwo",codeTwo);
		
					}
				} catch (Exception e) {
					log.error("----#---------#-验固码2失败--#---------#--",e);
				}
//	   	 }
//	   	if(!codeThree.equals(storeBatchDetail.getCodeThree())){
	   		//验证固码3是否正确
	   		 try {
	   			 	log.info("----#---------#-验证固码3开始--#---------#--");
					Map<String, String> map = ValidateUtil.codeThree(codeThree);
					log.info("----#---------#-验证固码3结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("codeThree",codeThree);
		
					}
				} catch (Exception e) {
					log.error("----#---------#-验固码3失败--#---------#--",e);
				}
//	   	 }
//	   	if(!codeFour.equals(storeBatchDetail.getCodeFour())){
	   		//验证固码4是否正确
	   		 try {
	   			 	log.info("----#---------#-验证固码4开始--#---------#--");
					Map<String, String> map = ValidateUtil.codeFour(codeFour);
					log.info("----#---------#-验证固码4结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("codeFour",codeFour);
		
					}
				} catch (Exception e) {
					log.error("----#---------#-验固码1失败--#---------#--",e);
				}
//	   	 }
	   	Map map = new HashMap();
	   	map.put("failReason", failReason.toString());
	   	map.put("trueMap", trueMap);
		return map;
	}
	//店铺的修改校验
	private Map vaidStore(Map<String, Object> trueMap, Map<String, Object> trueMapStore, 
			StoreBatchDetail storeBatchDetail, String salesmanId, String storeShortName, 
			String payeeMobileId, String payeeInidcardValid, String storeType, 
			String bankAccount, String prestorePhone, String categoryManName, 
			String categoryManCardno, String categoryInidcardValid, String agentId, String wecatRates, String alipayRates, String codeOne, String codeTwo, String codeThree, String codeFour, 
			String licenseNo, String storeFullName, String registerDate, String mainBusiness, String rgstaddress, String payeeInidcard) {
		// TODO Auto-generated method stub
		 StringBuffer failReason =new StringBuffer();
		 //1---------------是否修改了业务员编号--公共
//	   	 if(!salesmanId.equals(storeBatchDetail.getSalesmanId())){
	   		//验证业务员编号是否正确
	   		 try {
	   			 	log.info("----#---------#-验证业务员编号开始--#---------#--");
					Map<String, String> map = ValidateUtil.salesmanId(storeBatchDetail.getAgentId(),salesmanId);
					log.info("----#---------#-验证业务员编号结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
						
					}else{
						trueMap.put("salesmanId",salesmanId);
						trueMapStore.put("salesmanId",salesmanId);
					}
				} catch (Exception e) {
					log.error("----#---------#-验证业务员编号失败--#---------#--",e);
				}
//	   	 }
	   	 //2-----------------是否修改了店铺简称--公共
	   	 if(!storeShortName.equals(storeBatchDetail.getStoreShortName())){
	   		//验证店铺简称是否正确
	   		 try {
	   			 	log.info("----#---------#-验证店铺简称开始--#---------#--");
					Map<String, String> map = ValidateUtil.storeShortSame(storeShortName,storeBatchDetail.getMerId());
					log.info("----#---------#-验证店铺简称结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("storeShortName",storeShortName);
						trueMapStore.put("storeShortName",storeShortName);
					}
				} catch (Exception e) {
					log.error("----#---------#-验证店铺简称失败--#---------#--",e);
				}
	   	 }
	   //3-----------------是否修改了手机号--并修改所有手机号
	   	 if(!payeeMobileId.equals(storeBatchDetail.getPayeeMobileId())){
	   		//验证手机号是否正确
	   		 try {
	   			 	log.info("----#---------#-验证手机号开始--#---------#--");
					Map<String, String> map = payeeMobileTf(storeBatchDetail);
					log.info("----#---------#-验证手机号结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("payeeMobileId",payeeMobileId);
						trueMapStore.put("payeeMobileId",payeeMobileId);
						//可以修改的话直接修改
						//可以修改手机号
						ReqMessage req2 = new ReqMessage();		
						req2.put("merId",storeBatchDetail.getMerId());	//主商户号
						req2.put("payeeMobileId",payeeMobileId);	//手机号
						log.info("【修改子店铺手机号】入参：" + req2);
						StoreInfServiceRemote storeInfServiceRemote = DubboInvokerUtil.getInvoker(StoreInfServiceRemote.class);
						ResMessage res2 = storeInfServiceRemote.updateStoreByMerIdOrStoreId(req2);
						log.info("【修改子店铺手机号】出参：" + res2);
						if(!res2.getRetCode().equals(ConstantDefined.SUCCESS)){
							log.info("修改子店铺手机号失败");					
						}
						ReqMessage req3 = new ReqMessage();		
						req3.put("storeId",storeBatchDetail.getMerId());	//主商户号
						req3.put("payeeMobileId",payeeMobileId);	//手机号
						log.info("【修改主店铺手机号】入参：" + req3);
 						ResMessage res3 = storeInfServiceRemote.updateStoreByMerIdOrStoreId(req3);
						log.info("【修改主店铺手机号】出参：" + res3);
						if(!res3.getRetCode().equals(ConstantDefined.SUCCESS)){
							log.info("修改主店铺手机号失败");					
						}
					}
				} catch (Exception e) {
					log.error("----#---------#-验证手机号失败--#---------#--",e);
				}
	   	 }
	   	 //4-----------------是否修改了有效期--并修改所有有效期
	   	 if(!payeeInidcardValid.equals(storeBatchDetail.getPayeeInidcardValid())){
	   		//修改有效期
	   		 try {  			 	
					trueMap.put("payeeInidcardValid",payeeInidcardValid);
					trueMapStore.put("payeeInidcardValid",payeeInidcardValid);
					//可以修改的话直接修改
					//可以修改手机号
					ReqMessage req2 = new ReqMessage();		
					req2.put("merId",storeBatchDetail.getMerId());	//zi商户号
					req2.put("payeeInidcardValid",payeeInidcardValid);	//手机号
					log.info("【修改子店铺有效期】入参：" + req2);
					StoreInfServiceRemote storeInfServiceRemote = DubboInvokerUtil.getInvoker(StoreInfServiceRemote.class);
					ResMessage res2 = storeInfServiceRemote.updateInidcardValidByMerIdOrStoreId(req2);
					log.info("【修改子店铺有效期】出参：" + res2);
					if(!res2.getRetCode().equals(ConstantDefined.SUCCESS)){
						log.info("修改子店铺有效期失败");					
					}
					ReqMessage req3 = new ReqMessage();		
					req3.put("storeId",storeBatchDetail.getMerId());	//主商户号
					req3.put("payeeInidcardValid",payeeInidcardValid);	//手机号
					log.info("【修改主店铺有效期】入参：" + req3);
					ResMessage res3 = storeInfServiceRemote.updateInidcardValidByMerIdOrStoreId(req3);
					log.info("【修改主店铺有效期】出参：" + res3);
					if(!res3.getRetCode().equals(ConstantDefined.SUCCESS)){
						log.info("修改主店铺有效期失败");					
					}
					
				} catch (Exception e) {
					log.error("----#---------#-验证手机号失败--#---------#--",e);
				}
	   	 }
	     //5---------------是否修改了小微--公共
	   	 //TODOlicenseNo,storeFullName,categoryManName,categoryManCardno,categoryInidcardValid,registerDate,mainBusiness,rgstaddress
	   	 if(!storeType.equals(storeBatchDetail.getStoreType())){
	   		//验证修改了小微
	   		 if("0".equals(storeType)){
	   			 try {
		   			 	log.info("----#---------#-验证小微开始--#---------#--");
						Map<String, String> map =typeIf(storeBatchDetail);
						log.info("----#---------#-验证小微结束--#---------#--"+map.toString());
						if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
							failReason.append(map.get("retMsg"));
							failReason.append("|");
						}else{
							trueMap.put("storeType",storeType);
							trueMap.put("licenseNo","");
							trueMap.put("storeFullName","");
							trueMap.put("registerDate","");
							trueMap.put("mainBusiness","");
							trueMap.put("registerDate","");
							trueMap.put("rgstaddress","");									
							trueMap.put("categoryManName","");
							trueMap.put("categoryManCardno","");
							trueMap.put("categoryInidcardValid","");
							
							trueMapStore.put("storeType",storeType);
							trueMapStore.put("licenseNo","");
							trueMapStore.put("storeFullName","");
							trueMapStore.put("registerDate","");
							trueMapStore.put("mainBusiness","");
							trueMapStore.put("registerDate","");
							trueMapStore.put("rgstaddress","");
							trueMapStore.put("categoryManName","");
							trueMapStore.put("categoryManCardno","");
							trueMapStore.put("categoryInidcardValid","");
						}
					} catch (Exception e) {
						log.error("----#---------#-验证业务员编号失败--#---------#--",e);
					}
	   		 }else if("1".equals(storeType)){
	   			try {
	   			 	log.info("----#---------#-验证法人姓名.验证法人证件号.法人证件有效期开始--#---------#--");
					Map<String, String> map = ValidateUtil.storeManIdentity(categoryManName,categoryManCardno,categoryInidcardValid);
					log.info("----#---------#-验证法人姓名.验证法人证件号.法人证件有效期结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("categoryManName",categoryManName);
						trueMap.put("categoryManCardno",categoryManCardno);
						trueMap.put("categoryInidcardValid",categoryInidcardValid);
						trueMapStore.put("categoryManName",categoryManName);
						trueMapStore.put("categoryManCardno",DesIDUtil.encID(categoryManCardno));
						trueMapStore.put("categoryInidcardValid",categoryInidcardValid);
					}
				} catch (Exception e) {
					log.error("----#---------#-验证法人姓名.验证法人证件号.法人证件有效期失败--#---------#--",e);
				}
	   				trueMap.put("storeType","1");
					trueMap.put("licenseNo",licenseNo);
					trueMap.put("storeFullName",storeFullName);
					trueMap.put("registerDate",registerDate);
					trueMap.put("mainBusiness",mainBusiness);
					trueMap.put("registerDate",registerDate);
					trueMap.put("rgstaddress",rgstaddress);									
					trueMapStore.put("licenseNo",licenseNo);
					trueMapStore.put("storeFullName",storeFullName);
					trueMapStore.put("registerDate",registerDate);
					trueMapStore.put("mainBusiness",mainBusiness);
					trueMapStore.put("registerDate",registerDate);
					trueMapStore.put("rgstaddress",rgstaddress);
	   		}
	   		
	   	 }else{
	   		 //7---------------是否修改了法人姓名.验证法人证件号.法人证件有效期--公共 categoryManName categoryManCardno categoryInidcardValid
		   	 //licenseNo,storeFullName,categoryManName,categoryManCardno,categoryInidcardValid,registerDate,mainBusiness,rgstaddress
	   		 if("1".equals(storeType)){
//		   		if(!categoryManName.equals(storeBatchDetail.getCategoryManName()) || !categoryManCardno.equals(storeBatchDetail.getCategoryManCardno()) 
//			   			 ||  !categoryInidcardValid.equals(storeBatchDetail.getCategoryInidcardValid())){
			   		//验证业务员编号是否正确
			   		 try {
			   			 	log.info("----#---------#-验证法人姓名.验证法人证件号.法人证件有效期开始--#---------#--");
							Map<String, String> map = ValidateUtil.storeManIdentity(categoryManName,categoryManCardno,categoryInidcardValid);
							log.info("----#---------#-验证法人姓名.验证法人证件号.法人证件有效期结束--#---------#--"+map.toString());
							if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
								failReason.append(map.get("retMsg"));
								failReason.append("|");
							}else{
								trueMap.put("categoryManName",categoryManName);
								trueMap.put("categoryManCardno",DesIDUtil.encID(categoryManCardno));
								trueMap.put("categoryInidcardValid",categoryInidcardValid);
								trueMapStore.put("categoryManName",categoryManName);
								trueMapStore.put("categoryManCardno",DesIDUtil.encID(categoryManCardno));
								trueMapStore.put("categoryInidcardValid",categoryInidcardValid);
							}
						} catch (Exception e) {
							log.error("----#---------#-验证法人姓名.验证法人证件号.法人证件有效期失败--#---------#--",e);
						}
			   		 //
			   		trueMap.put("storeType",storeType);
			   		trueMap.put("licenseNo",licenseNo);
					trueMap.put("storeFullName",storeFullName);
					trueMap.put("registerDate",registerDate);
					trueMap.put("mainBusiness",mainBusiness);
					trueMap.put("registerDate",registerDate);
					trueMap.put("rgstaddress",rgstaddress);									
					trueMapStore.put("licenseNo",licenseNo);
					trueMapStore.put("storeFullName",storeFullName);
					trueMapStore.put("registerDate",registerDate);
					trueMapStore.put("mainBusiness",mainBusiness);
					trueMapStore.put("registerDate",registerDate);
					trueMapStore.put("rgstaddress",rgstaddress);
					
//			   	 }
		   	 }else{
		   		trueMap.put("storeType","0");
		   	 }
	   	 }
		 //6---------------是否修改了银行卡和手机号--公共
//	   	 if(!bankAccount.equals(storeBatchDetail.getBankAccount()) || !prestorePhone.equals(storeBatchDetail.getPrestorePhone())){
	   		//验证业务员编号是否正确
	   		 try {
	   			 	log.info("----#---------#-验证银行卡和手机号开始--#---------#--");
					Map<String, String> map = ValidateUtil.bankAccount(storeBatchDetail.getPayeeName(),payeeInidcard,bankAccount,prestorePhone);
					log.info("----#---------#-验证银行卡和手机号结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("bankAccount",DesIDUtil.encID(bankAccount));
						trueMap.put("prestorePhone",prestorePhone);
//						trueMapStore.put("prestorePhone",prestorePhone);
//						trueMapStore.put("prestorePhone",prestorePhone);
					}
				} catch (Exception e) {
					log.error("----#---------#-验证银行卡和手机号失败--#---------#--",e);
				}
//	   	 }
	   	
	   	 //8---------------是否修改了验证立马付微信、支付宝费率 agentId wecatRates alipayRates--公共
//	   	 if(!wecatRates.equals(storeBatchDetail.getWecatRates()) || !alipayRates.equals(storeBatchDetail.getAlipayRates())){
	   		//验证立马付微信、支付宝费是否正确
	   		 try {
	   			 	log.info("----#---------#-验证立马付微信、支付宝费开始--#---------#--");
					Map<String, String> map = ValidateUtil.rate(agentId,wecatRates,alipayRates);
					log.info("----#---------#-验证立马付微信、支付宝费结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
//						trueMap.put("wecatRates",wecatRates);
//						trueMap.put("alipayRates",alipayRates);
						trueMap.put("wecatRates",wecatRates.equals("") ? "" : (new BigDecimal(wecatRates).multiply(new BigDecimal(1000))).intValue());//立马付微信费率（%）
						trueMap.put("alipayRates",alipayRates.equals("") ? "" : (new BigDecimal(alipayRates).multiply(new BigDecimal(1000))).intValue());//立马付支付宝费率（%）

					}
				} catch (Exception e) {
					log.error("----#---------#-验证立马付微信、支付宝费失败--#---------#--",e);
				}
//	   	 }
	   //9---------------是否修改了.固码codeOne codeTwo codeThree codeFour--公共
//	   	 if(!codeOne.equals(storeBatchDetail.getCodeOne())){
	   		//验证固码1是否正确
	   		 try {
	   			 	log.info("----#---------#-验证固码1开始--#---------#--");
					Map<String, String> map = ValidateUtil.codeOne(codeOne);
					log.info("----#---------#-验证固码1结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("codeOne",codeOne);
		
					}
				} catch (Exception e) {
					log.error("----#---------#-验固码1失败--#---------#--",e);
				}
//	   	 }
//	   	if(!codeTwo.equals(storeBatchDetail.getCodeTwo())){
	   		//验证固码2是否正确
	   		 try {
	   			 	log.info("----#---------#-验证固码2开始--#---------#--");
					Map<String, String> map = ValidateUtil.codeTwo(codeTwo);
					log.info("----#---------#-验证固码2结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("codeTwo",codeTwo);
		
					}
				} catch (Exception e) {
					log.error("----#---------#-验固码2失败--#---------#--",e);
				}
//	   	 }
//	   	if(!codeThree.equals(storeBatchDetail.getCodeThree())){
	   		//验证固码3是否正确
	   		 try {
	   			 	log.info("----#---------#-验证固码3开始--#---------#--");
					Map<String, String> map = ValidateUtil.codeThree(codeThree);
					log.info("----#---------#-验证固码3结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("codeThree",codeThree);
		
					}
				} catch (Exception e) {
					log.error("----#---------#-验固码3失败--#---------#--",e);
				}
//	   	 }
//	   	if(!codeFour.equals(storeBatchDetail.getCodeFour())){
	   		//验证固码4是否正确
	   		 try {
	   			 	log.info("----#---------#-验证固码4开始--#---------#--");
					Map<String, String> map = ValidateUtil.codeFour(codeFour);
					log.info("----#---------#-验证固码4结束--#---------#--"+map.toString());
					if(!"0000".equals(map.get("retCode"))){	//查询店铺详情失败或异常
						failReason.append(map.get("retMsg"));
						failReason.append("|");
					}else{
						trueMap.put("codeFour",codeFour);
		
					}
				} catch (Exception e) {
					log.error("----#---------#-验固码1失败--#---------#--",e);
				}
//	   	 }
	   	Map map = new HashMap();
	   	map.put("failReason", failReason.toString());
	   	map.put("trueMap", trueMap);
	   	map.put("trueMapStore", trueMapStore);
		return map;
	}
	private Map<String, String> payeeMobileTf(StoreBatchDetail storeBatchDetail) {
		log.info("【开始验证手机号是否能修改】") ;
														
		ReqMessage req = new ReqMessage();	
		Map<String, String> map = new HashMap<String, String>();
		req.put("merId",storeBatchDetail.getMerId());
		try {
			log.info("【查询店铺列表信息】入参：" + req);
			StoreInfServiceRemote storeInfServiceRemote = DubboInvokerUtil.getInvoker(StoreInfServiceRemote.class);
			ResMessage res = storeInfServiceRemote.getStoreInfList(req);
			log.info("【查询店铺列表信息】出参参：" + res);
			if(!res.getRetCode().equals(ConstantDefined.SUCCESS)){
				log.info("统计店铺列表查询失败");
				map.put("retCode", "1111");
				map.put("retMsg", "校验商户简称失败，请重试");
				return map;
			}
			Integer totalSize = (Integer) res.getResMap().get("totalSize");
			List<MerchantInfo> merchantInfos = (List<MerchantInfo>) res.getResMap().get(XmlData.STORE_INF_LIST);		
			if (totalSize > 1) {	//大于1，说明有其它子店铺
				for (int i = 0; i < merchantInfos.size(); i++) {	//不能修改手机号
					if("0".equals(merchantInfos.get(i).getType())){
						if (merchantInfos.get(i).getRegisterProcsState().equals("06")
								|| merchantInfos.get(i).getRegisterProcsState().equals("07")
								|| merchantInfos.get(i).getRegisterProcsState().equals("08")
								|| merchantInfos.get(i).getRegisterProcsState().equals("09")) {
							map.put("retCode", "1111");
							map.put("retMsg", "不能修改手机号");	
				 			return map;
						}
					}else if("1".equals(merchantInfos.get(i).getType())){
						if (merchantInfos.get(i).getRegisterProcsState().equals("08")) {
							map.put("retCode", "1111");
							map.put("retMsg", "不能修改手机号");	
				 			return map;
						}
					}
					
				}
									
			}
		} catch (Exception e) {
			log.error("【验证手机号是否能修改】异常", e);
			map.put("retCode", "1111");
			map.put("retMsg", "验证手机号是否能修改失败，请重试");
			return map;
		}	
		map.put("retCode", "0000");
		return map;
	}
	
	//判断是否能改小微
	private Map<String, String> typeIf(StoreBatchDetail storeBatchDetail) {
		log.info("判断是否能改小微是否能修改】") ;
																
		Map<String, String> map = new HashMap<String, String>();
		map.put("merId",storeBatchDetail.getMerId());

		try {
			//~~~~~~~~~~~~~~~~~如果用户开小微店铺，则需要判断一下用户有没有开通提前结算产品、有没有开通基金产品~~~~~~~~~~~~~~~~~
			
			ReqMessage reqChanne = ReqMessageUtil.makeOpReq();
			reqChanne.put("storeId",storeBatchDetail.getMerId());//应用编号 60000680
			//reqChanne.put("productId",PRODUCTID_ADVANCESETTLE);//模板编号
			log.info("【根据主键查询渠道表接口】入参：" + reqChanne);
			 AppChannelServiceRemote appChannelServiceRemote = DubboInvokerUtil.getInvoker(AppChannelServiceRemote.class);

			ResMessage resChanne =appChannelServiceRemote.queryListAppChannel(reqChanne);
			log.info("【根据主键查询渠道表接口】出参：" + resChanne);
			if ("0000".equals(resChanne.getRetCode())) {	//返回成功，说明已经开通了提前结算产品
				List<AppChannel> appChannels = (List<AppChannel>) resChanne.getValue("resultList");
				for (AppChannel appChannel : appChannels) {
					if (PRODUCTID_ADVANCESETTLE.equals(appChannel.getProductId())) {						
						map.put("retCode", "1111");
						map.put("retMsg", "您已开通了提前结算产品，暂不支持同时开通小微店铺");
						log.error("【根据主键查询渠道表】成功，说明：已开通了提前结算产品，暂不支持同时开通小微店铺");
						return map;
					}
				}
			}
			ReqMessage reqFund = ReqMessageUtil.makeOpReq();
			reqFund.put("merId",storeBatchDetail.getMerId()); //主商户号 68000044
			log.info("【基金企业/个人开户信息查询】入参" + reqFund);
			FundServiceRemote fundServiceRemote = DubboInvokerUtil.getInvoker(FundServiceRemote.class);

			ResMessage resFund = fundServiceRemote.queryFundMerInfo(reqFund);
			log.info("【基金企业/个人开户信息查询】返回参数：" + resFund);
			if ("0000".equals(resFund.getRetCode())) {
				map.put("retCode", "1111");
				map.put("retMsg", "您已开通了基金产品，暂不支持同时开通小微店铺");
				log.info("【查询商户是否开通基金产品】成功，说明：已开通了基金产品，暂不支持同时开通小微店铺");
				return map;							
			}
			
		} catch (Exception e) {							
			log.error("【判断是否能改小微】异常", e);
			map.put("retCode", "1111");
			map.put("retMsg", "判断是否能改小微，请重试");
			return map;
		}	
		map.put("retCode", "0000");
		return map;
	}
	/**
	 *  变更为‘待审核’插入操作记录
	 * @param storeInf	店铺详情
	 * @param res	 
	 * @return
	 */
	public com.umpay.operation.common.ResMessage addJoinFlowForCheckMer(MerchantInfo storeInf){
		
		com.umpay.operation.common.ResMessage res = null;
		com.umpay.operation.common.ReqMessage req = ReqMessageUtil.makeOpReq();
		try {
			
		req.put("merUniformId",storeInf.getStoreId());	//商户唯一标识
		req.put("handleState","0");	//申请处理状态
		req.put("handleState","0");	//申请处理状态   0-初始 1-完成
		req.put("handleStep","自动开通待复查");	//处理节点  中文描述
		req.put("handleRole","00");	//处理人角色：00系统自动；01财务； 02运营； 03客服 ；04商户 ；99其他		
		log.info("----#---------#--变更为‘待复查’插入操作记录，请求参数：--#---------#--" + req);
		JoinFlowServiceRemote joinFlowServiceRemote = DubboInvokerUtil.getInvoker(JoinFlowServiceRemote.class);
		res = joinFlowServiceRemote.add(req);
		log.info("----#---------#--变更为‘待复查’插入操作记录，返回参数：--#---------#--" + res);
		} catch (Exception e) {
			log.error(storeInf.getStoreId() +"----#---------#--变更为‘待复查’插入操作记录异常--#---------#--" , e);		
		}
		return res;
	}
	/**
	 *  变更为‘已删除’插入操作记录
	 * @param storeInf	店铺详情
	 * @param res	 
	 * @return
	 */
	public com.umpay.operation.common.ResMessage addJoinFlowForDelMer(MerchantInfo storeInf){
		
		com.umpay.operation.common.ResMessage res = null;
		com.umpay.operation.common.ReqMessage req = ReqMessageUtil.makeOpReq();
		try {
			
		req.put("merUniformId",storeInf.getStoreId());	//商户唯一标识
 		req.put("handleState","0");	//申请处理状态   0-初始 1-完成
		req.put("handleStep","已删除");	//处理节点  中文描述
		req.put("handleRole","00");	//处理人角色：00系统自动；01财务； 02运营； 03客服 ；04商户 ；99其他	
		req.put("handleUser",StringUtil.trim(this.getSession().get(XmlData.AGENTID)));
		log.info("----#---------#--变更为‘已删除’插入操作记录，请求参数：--#---------#--" + req);
		JoinFlowServiceRemote joinFlowServiceRemote = DubboInvokerUtil.getInvoker(JoinFlowServiceRemote.class);
		res = joinFlowServiceRemote.add(req);
		log.info("----#---------#--变更为已删除’插入操作记录，返回参数：--#---------#--" + res);
		} catch (Exception e) {
			log.error(storeInf.getStoreId() +"----#---------#--变更为‘已删除’插入操作记录异常--#---------#--" , e);		
		}
		return res;
	}
	/**
	 * 下载图片
	 * 
	 * @return
	 */
	public String uploadStoreDetiledById(){
		log.info("【下载照片】开始");
		try{			
			String uuid =  request.getParameter("uuid");
			String batchNo =request.getParameter("batchNo");
		    log.info("-----前端参数batchNo= " +batchNo+"uuid ="+uuid);
			ReqMessage req = new ReqMessage();	
			req.put("uuid", uuid);
			req.put("batchNo",batchNo);//可以出来
			log.info("【查询批量明细信息】入参：" + req);
 			TStoreBatchDetailServiceRemote tStoreBatchDetailServiceRemote = DubboInvokerUtil.getInvoker(TStoreBatchDetailServiceRemote.class);
			ResMessage res = tStoreBatchDetailServiceRemote.getBatchDetailByPri(req);
			log.info("【查询批量明细信息】出参：" + res);
 			if(!res.getRetCode().equals(ConstantDefined.SUCCESS)){
				log.info("统计批量明细查询失败");
				//return ERROR;
			}
			StoreBatchDetail storeBatchDetail = (StoreBatchDetail) res.getResMap().get(XmlData.STORE_BATCH_DETAIL);
			if(storeBatchDetail != null){
				log.info("【查询批量明细信息】出参：" + storeBatchDetail.toString());		 	 
			}	
			String plzipLocation = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","plzipLocation", "");
			//D:/duhao/
			String downFileName = batchNo+"&"+uuid+".zip";
			String fileName = storeBatchDetail.getStoreShortName()+"（"+storeBatchDetail.getStoreId()+"）.zip";
			File file=new File(plzipLocation+storeBatchDetail.getImgUrl());			  			  
 		   
 		    BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(file));
			//根据浏览器设置文件名称
		    FileUtil.setFileNameByBrowser(fileName, request, response);
	        //流输出文件
	        OutputStream out = new BufferedOutputStream(response.getOutputStream());
		    byte[] buf = new byte[1024];
		    int len = 0;
		    while ((len = inStream.read(buf)) > 0){
		    	out.write(buf, 0, len);
		    }
		    inStream.close();
		    out.close();
		    log.info("下载照片！");	   
			return null;
		}catch(Exception e){
			e.printStackTrace();
			log.error("下载照片失败", e);
			return ERROR;
		}
	}
	
	/**
	 * 上传照片
	 * @throws IOException
	 */
	public void doUploadfile() throws IOException {
 		 
		try {
			log.info("上传照片----------------开始：" );
			String plzipLocation = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","plzipLocation", "");
				//D:/duhao
 		    log.info("-----前端参数batchNo= " +batchNo+"uuid ="+uuid +"totype ="+toType);
			File file2 = new File(plzipLocation);
			String fileName = batchNo+"&"+uuid+".zip";
		    if(!file2.exists()) file2.mkdirs();	        
	        FileUtils.copyFile(uploadify, new File(file2, fileName));	       
	       
        	//查询关闭产品
			ReqMessage req = new ReqMessage();	
			req.put("uuid",  uuid);
			req.put("batchNo",batchNo);
			log.info("【查询批量明细信息】入参：" + req);
 			TStoreBatchDetailServiceRemote tStoreBatchDetailServiceRemote = DubboInvokerUtil.getInvoker(TStoreBatchDetailServiceRemote.class);
			ResMessage res = tStoreBatchDetailServiceRemote.getBatchDetailByPri(req);
			log.info("【查询批量明细信息】出参：" + res);
 			if(!res.getRetCode().equals(ConstantDefined.SUCCESS)){
				log.info("统计批量明细查询失败");
				//return ERROR;
			}
			StoreBatchDetail storeBatchDetail = (StoreBatchDetail) res.getResMap().get(XmlData.STORE_BATCH_DETAIL);
			if(storeBatchDetail != null){
				log.info("【查询批量明细信息】出参：" + storeBatchDetail.toString());
 			}
			//修改
			ReqMessage req2 = new ReqMessage();	
			 if("03".equals(storeBatchDetail.getRegisterProcsState())){
				 storeBatchDetail.setRegisterProcsState("07");
				
				 ReqMessage req3 = new ReqMessage();		
					req3.put("storeId",storeBatchDetail.getStoreId());	//店铺编号
					log.info("【查询店铺信息】入参：" + req3);
					StoreInfServiceRemote storeInfServiceRemote = DubboInvokerUtil.getInvoker(StoreInfServiceRemote.class);
					ResMessage res3 = storeInfServiceRemote.getStoreInfByPri(req3);
					log.info("【查询店铺信息】出参：" + res3);
					 
					if(!res.getRetCode().equals(ConstantDefined.SUCCESS)){
						log.info("统计批次列表查询失败");
						//return ERROR;
					}
					MerchantInfo merchantInfo = (MerchantInfo) res3.getValue("merchantInfo");			
					if(merchantInfo != null){
						log.info("【查询店铺列表信息】入参：" + merchantInfo.toString());
 					}				
					
					ReqMessage req4 = new ReqMessage();	
					merchantInfo.setRegisterProcsState("07");
					//加入审批流程表
		  			log.info("变更为‘待复查’插入操作记录 ------");	
		  			addJoinFlowForCheckMer(merchantInfo);
					Map<String, Object> storeMap3 = SaasPropertyUtil.javaBeanToMapO(merchantInfo);	
					req4.putAll(storeMap3);
				 
					log.info("【修改店铺信息】入参：" + req4);
 			 		ResMessage res4 = storeInfServiceRemote.updateStoreInfAll(req4);
					log.info("【修改店铺信息】出参：" + res4);
 					if(!res4.getRetCode().equals(ConstantDefined.SUCCESS)){
						log.info("修改店铺信息失败");
						//return ERROR;
					}
			 }
			storeBatchDetail.setImgUrl(fileName);
			Map<String, Object> storeMap3 = SaasPropertyUtil.javaBeanToMapO(storeBatchDetail);	
			req2.putAll(storeMap3);			
			log.info("【修改批量明细信息】入参：" + req);
 			ResMessage res2 = tStoreBatchDetailServiceRemote.updateBatchDetailByPri(req2);
			
			log.info("【修改批量明细信息】出参：" + res2);			 
			response.getWriter().write("0000");
		} catch (Exception e) {
			log.error("【上传Excel文件】异常", e);
			response.getWriter().write("1111");
			return;
		}
	}
	
}
